package com.googlecode.struts2.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.googlecode.allinclusive.fw.valueobject.UserObject;
import com.googlecode.biz.Z1000Biz;
import com.googlecode.entity.SalesEntity;
import com.opensymphony.xwork2.ActionContext;

public class Z1000WAction extends BaseDispatcherAction implements SessionAware, RequestAware {
	
	@Autowired
	Z1000Biz z1000Biz;

	/**
	 * login
	 * @return
	 */
	public String login() {
		UserObject userObject = z1000Biz.login(shinryojoId, riyoshaId);

		if (userObject == null) {
			return "syserr";
		}
		
		// セッションに格納(非IOC)
		ActionContext.getContext().getSession().put(UserObject.USER_OBJECT_KEY, userObject);
		// セッションに格納(IOC方式　servletConfig Interceptor is necessary)
		session.put(UserObject.USER_OBJECT_KEY, userObject);
		
		return "success";
	}
	
	/**
	 * select all sale informations
	 * @return
	 */
	public String select() {
		
		List<SalesEntity> sales = z1000Biz.selectSales();
		request.put("sales", sales);		
		return "Z1001W";
	}

	// jsp form elem
	private String shinryojoId;
	private String riyoshaId;
	public String getShinryojoId() {
		return shinryojoId;
	}
	public void setShinryojoId(String shinryojoId) {
		this.shinryojoId = shinryojoId;
	}
	public String getRiyoshaId() {
		return riyoshaId;
	}
	public void setRiyoshaId(String riyoshaId) {
		this.riyoshaId = riyoshaId;
	}

	// IOC方式
	private Map<String, Object> session;
	private Map<String, Object> request;
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
}
